package org.chen.scene.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.chen.common.scene.task.GrabTaskLog;

import java.util.List;
import java.util.Map;

@Mapper
public interface GrabTaskLogMapper extends BaseMapper<GrabTaskLog> {
    
    /**
     * 查询任务的执行历史统计
     */
    @Select("SELECT " +
            "COUNT(*) as executeCount, " +
            "SUM(total_count) as totalCount, " +
            "SUM(new_count) as totalNewCount, " +
            "SUM(update_count) as totalUpdateCount " +
            "FROM scene_grab_task_log " +
            "WHERE task_id = #{taskId} AND status = 'SUCCESS'")
    Map<String, Object> getTaskExecuteStats(@Param("taskId") Long taskId);
    
    /**
     * 查询最近的执行日志
     */
    @Select("SELECT * FROM scene_grab_task_log " +
            "WHERE task_id = #{taskId} " +
            "ORDER BY create_time DESC " +
            "LIMIT #{limit}")
    List<GrabTaskLog> getRecentLogs(@Param("taskId") Long taskId, @Param("limit") Integer limit);
}
